<template>
    <div class="pages addTitle">
      <div class="g-container" id="container">
       <group>
          <div class="weui-cell">
            <div class="weui-cell__bd">
              <input type="text" class="weui-input" placeholder="请输入企业名称" @input="inputTitle" v-model.trim="title" > 
            </div>
            <div class="weui-cell__hd" style="color:#119EDD;padding-left:10px;" @click='sure'>确定</div>
          </div>
          <div class="weui-cell" v-for="list in indexMap" :key="list">
            <div class="weui-cell__bd" style="color: #646464;" @click='searchNew(list.c_code,list.validator,list.signid,list.invoicetype)'>
              {{list.c_kpname}}
            </div>
          </div>
       </group>
      </div>
    </div>
</template>
<script>
import { Group,Panel ,Cell,XInput } from 'vux'
import qs from 'Qs'
import store from 'storejs';
export default {
  name: 'addTitle',
  components:{
    Group, Panel, XInput, Cell,
  },
  data () {
    return {
      indexMap:'',
      form:{
        kpname:'',
        kpcode:'',
        kpaddr:'',
        kptel:'',
        code:'',
        kpbank:'',
        kpaccount:''
      },
      title:'',
      counter:0,
      value:''
    }
  },
  created: function(){
    
  },
  computed:{
		disabled(){
			return  !this.title!='' ?true:false;
		}
  },
  methods:{
    sure(){
      var title = this.title;
      if(title.length<3){
        this.$vux.toast.show({
          type:'text',
          width:'70%',
          text: '请输入至少三个字符'
        });
      }else{
        this.form.kpname = this.title;
        store({'infoT':this.form});
        this.$router.push({path:'/index'});
      }
    },
    inputTitle:function () {
      var that = this,timer;
      var vlength = that.title.length;
      clearTimeout(timer);
      timer = setTimeout(function () {
        if(vlength>2) {
          //是汉字的时候实时搜索
          var reg = /^[\u4e00-\u9fa5]+/i; 
          if (reg.test(that.title)){
              that.searchInput(that.title);
          }else if(that.title && /^[A-Za-z0-9]{6}$/g.test(that.title)){
              that.searchInput(that.title);
          }
        }else{
            //字数不足
        }
      },200);
    },
    searchInput:function (val){
      var timestamp = (new Date()).valueOf();
      this.$http.get('/static/findInvoiceMake.action',{params:{ paramName:val,timestamp:timestamp}}).then((response)=>{
        var datas = response.data;
        console.log(typeof datas)
        if(datas){
            this.indexMap = datas.list;
          }else{
            this.indexMap='';
          }
      },(response) => {
					console.log(response.data)
      })
    },
    searchNew(val,validator,signid,invoicetype){
      console.log(val,validator,signid);
      this.$http.get('https://bird.ioliu.cn/v1/?url=http://jskp.jss.com.cn/portal/allow/qrbarcodes/findTzUserinfoForRequestkp.action?code=ZJHTXX&validator=ZJHTXX&signid=f757034bf707a4ebb56307b8044737b7').then((response) => {
					var datas = response.data;
          console.log(datas)
					if(datas){
					 	this.form.kpname=datas.kpName;
					 	this.form.kpcode=datas.kpCode;
						this.form.kpaddr=datas.kpAddr;
						this.form.kptel=datas.kpTel;
            this.form.code = datas.code;
						this.form.kpbank=datas.accountBlank;
						this.form.kpaccount=datas.bankAccount;
            store({'infoT':this.form});
            this.$router.push({path:'/index'});
					}
				}, (response) => {
					
				});
    }
  }
}
</script>

<style scoped lang="less">
.addTitle{
  .weui-input{
    color: #646464;
    width: 100%;
    border: 0;
    outline: 0;
    -webkit-appearance: none;
    background-color: transparent;
    font-size: inherit;
    color: inherit;
    height: 1.41176471em;
    line-height: 1.41176471;
  }
}
</style>
